]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status: Add nightLight indicator
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 10 Feb 2017 13:14:14 +0000 (14:14 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 15 Feb 2017 22:20:14 +0000 (23:20 +0100)
The display configuration now exposes a setting to automatically
shift the display color at nighttime. As there are cases where
disabling the filtering temporarily is useful, it makes sense to
expose the feature in the system menu for quick access.

https://bugzilla.gnome.org/show_bug.cgi?id=741224

js/js-resources.gresource.xml
js/ui/panel.js
js/ui/status/nightLight.js [new file with mode: 0644]

index 58f433c3c5ceaf1ca7ac321aaf4b5a73f5ce1825..72cc4f8753afd2198aaa5c7ff5c32b378ee2d622 100644 (file)
     <file>ui/status/brightness.js</file>
     <file>ui/status/location.js</file>
     <file>ui/status/keyboard.js</file>
+    <file>ui/status/nightLight.js</file>
     <file>ui/status/network.js</file>
     <file>ui/status/power.js</file>
     <file>ui/status/rfkill.js</file>
index aad466df7c0c8dcdb45a11c16806dec5cc7d5db6..fe3fc392f8025e39b6022745c30d40e0da650688 100644 (file)
@@ -719,9 +719,11 @@ const AggregateMenu = new Lang.Class({
         this._system = new imports.ui.status.system.Indicator();
         this._screencast = new imports.ui.status.screencast.Indicator();
         this._location = new imports.ui.status.location.Indicator();
+        this._nightLight = new imports.ui.status.nightLight.Indicator();
 
         this._indicators.add_child(this._screencast.indicators);
         this._indicators.add_child(this._location.indicators);
+        this._indicators.add_child(this._nightLight.indicators);
         if (this._network) {
             this._indicators.add_child(this._network.indicators);
         }
@@ -745,6 +747,7 @@ const AggregateMenu = new Lang.Class({
         this.menu.addMenuItem(this._location.menu);
         this.menu.addMenuItem(this._rfkill.menu);
         this.menu.addMenuItem(this._power.menu);
+        this.menu.addMenuItem(this._nightLight.menu);
         this.menu.addMenuItem(this._system.menu);
 
         menuLayout.addSizeChild(this._location.menu.actor);
diff --git a/js/ui/status/nightLight.js b/js/ui/status/nightLight.js
new file mode 100644 (file)
index 0000000..b97710c
--- /dev/null
@@ -0,0 +1,74 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+
+const Main = imports.ui.main;
+const PanelMenu = imports.ui.panelMenu;
+const PopupMenu = imports.ui.popupMenu;
+
+const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
+const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
+
+const ColorInterface = '<node> \
+<interface name="org.gnome.SettingsDaemon.Color"> \
+  <property name="DisabledUntilTomorrow" type="b" access="readwrite"/> \
+  <property name="NightLightActive" type="b" access="read"/> \
+</interface> \
+</node>';
+
+const ColorProxy = Gio.DBusProxy.makeProxyWrapper(ColorInterface);
+
+const Indicator = new Lang.Class({
+    Name: 'NightLightIndicator',
+    Extends: PanelMenu.SystemIndicator,
+
+    _init: function() {
+        this.parent();
+
+        this._indicator = this._addIndicator();
+        this._indicator.icon_name = 'night-light-symbolic';
+        this._proxy = new ColorProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
+                                     (proxy, error) => {
+                                         if (error) {
+                                             log(error.message);
+                                             return;
+                                         }
+                                         this._proxy.connect('g-properties-changed',
+                                                             Lang.bind(this, this._sync));
+                                         this._sync();
+                                     });
+
+        this._item = new PopupMenu.PopupSubMenuMenuItem("", true);
+        this._item.icon.icon_name = 'night-light-symbolic';
+        this._disableItem = this._item.menu.addAction('', () => {
+            this._proxy.DisabledUntilTomorrow = !this._proxy.DisabledUntilTomorrow;
+        });
+        this._item.menu.addAction(_("Turn Off"), () => {
+            let settings = new Gio.Settings({ schema_id: 'org.gnome.settings-daemon.plugins.color' });
+            settings.set_boolean('night-light-enabled', false);
+        });
+        this._item.menu.addSettingsAction(_("Display Settings"), 'gnome-display-panel.desktop');
+        this.menu.addMenuItem(this._item);
+
+        Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
+        this._sessionUpdated();
+        this._sync();
+    },
+
+    _sessionUpdated: function() {
+        let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
+        this.menu.setSensitive(sensitive);
+    },
+
+    _sync: function() {
+        let visible = this._proxy.NightLightActive;
+        let disabled = this._proxy.DisabledUntilTomorrow;
+
+        this._item.label.text = disabled ? _("Night Light Disabled")
+                                         : _("Night Light On");
+        this._disableItem.label.text = disabled ? _("Resume")
+                                                : _("Disable Until Tomorrow");
+        this._item.actor.visible = this._indicator.visible = visible;
+    }
+});